home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / Tickle-4.0 (tcl) / library / help / tcl / control / uplevel < prev    next >
Encoding:
Text File  |  1993-10-26  |  2.3 KB  |  52 lines  |  [TEXT/$Tcl]

  1.  
  2.           uplevel ?level? arg ?arg ...?
  3.  
  4.  
  5.      DESCRIPTION
  6.           All of the arg arguments are concatenated  as  if  they  had
  7.           been  passed  to concat; the result is then evaluated in the
  8.           variable context indicated by level.   Uplevel  returns  the
  9.           result of that evaluation.
  10.  
  11.           If level is an integer then it gives a distance (up the pro-
  12.           cedure  calling stack) to move before executing the command.
  13.           If level consists of # followed by a number then the  number
  14.           gives an absolute level number.  If level is omitted then it
  15.           defaults to 1.  Level cannot be defaulted if the first  com-
  16.           mand argument starts with a digit or #.
  17.  
  18.           For example, suppose that procedure a was invoked from  top-
  19.           level,  and  that it called b, and that b called c.  Suppose
  20.           that c invokes the uplevel command.  If level is 1 or #2  or
  21.           omitted,  then  the command will be executed in the variable
  22.           context of b.  If level is 2 or #1 then the command will  be
  23.           executed  in the variable context of a.  If level is 3 or #0
  24.           then the command will be executed at top-level (only  global
  25.           variables will be visible).
  26.  
  27.           The uplevel command causes the invoking procedure to  disap-
  28.           pear  from  the procedure calling stack while the command is
  29.           being executed.  In the above example, suppose c invokes the
  30.           command
  31.  
  32.                uplevel 1 {set x 43; d}
  33.  
  34.           where d is another Tcl  procedure.   The  set  command  will
  35.           modify  the variable x in b's context, and d will execute at
  36.           level 3, as if called from b.  If it in  turn  executes  the
  37.           command
  38.  
  39.                uplevel {set x 42}
  40.           then the set command will modify the same variable x in  b's
  41.           context:   the procedure c does not appear to be on the call
  42.           stack when d is executing.  The command ``info  level''  may
  43.           be used to obtain the level of the current procedure.
  44.  
  45.           Uplevel makes it possible  to  implement  new  control  con-
  46.           structs  as  Tcl  procedures  (for example, uplevel could be
  47.           used to implement the while construct as a Tcl procedure).
  48.  
  49.  
  50.      KEYWORDS
  51.           context, stack frame, variables
  52.